<?php

namespace app\index\model;

use think\Model;


class Videocomment extends Model
{
    // 表名
    protected $name = 'video_comment';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 定义时间戳字段名
    protected $createTime = "create_time";
    protected $updateTime = "update_time";
    public $append=[
      'memberinfo',
      'parentinfo'
    ];
    public function getMemberinfoAttr($value,$data){
      return db('members')->field('nickname,avatar')->where('member_id',$data['member_id'])->find();
    }
    public function getParentinfoAttr($value,$data){
      return db('members')->field('nickname,avatar')->where('member_id',$data['parent_id'])->find();
    }
    public function getCreateTimeAttr($value){
       if(time()-$value<60){
        return '刚刚';
       }else if(time()-$value>60&&time()-$value<3600){
            return ceil($value/60);
       }else if(time()-$value>3600&&time()-$value<86400){
            return "今天";
       }else if(time()-$value>86400&&time()-$value<172800){
            return "昨天";
       }else{
            return date("Y-m-d",$value);
       }
    }
}
